#include <stdio.h>
#include <functional>

struct Foo {
    Foo(int num): num_(num) {}
    void print_add(int i) const { printf("%d\n", num_ + i); }
    int num_;
};

void print_num(int i) {
    printf("%d\n", i);
}

struct PrintNum {
    void operator()(int i) const {
        printf("%d\n", i);
    }
};

int main() {
    std::function<void (int)> f_display = print_num;
    f_display(-9);

    std::function<void ()> f_display_42 = []() { print_num(42); };
    f_display_42();

    std::function<void (const Foo&, int)> f_add_display = &Foo::print_add;
    const Foo foo(123);
    f_add_display(foo, 1);
    f_add_display(124, 1);

    using std::placeholders::_1;
    std::function<void (int)> f_add_display2 = std::bind(&Foo::print_add, foo, _1);
    f_add_display2(2);

    std::function<void (int)> f_add_display3 = std::bind(&Foo::print_add, &foo, _1);
    f_add_display3(2);

    std::function<void (int)> f_display_obj = PrintNum();
    f_display_obj(18);

    return 0;
}
